#import "Map.h"

@implementation Map

- (id)initWithFrame:(struct CGRect)frame 
{
	if ((self == [super initWithFrame:frame]) != nil)  {
	 
	 	dLoad = nil;
		isLoading = NO;
					 
		wView = [[UIWebView alloc] initWithFrame:frame];
		[wView setAutoresizes:YES];
		[wView setDelegate:self];
		[wView setTapDelegate:self];

		WebView *mCoreWebView = [wView webView];
		[mCoreWebView setFrameLoadDelegate:self];
		[mCoreWebView setPolicyDelegate:self];
		[mCoreWebView setUIDelegate:self];
		[mCoreWebView setResourceLoadDelegate:self];

  		[self addSubview:wView];				
  	}
  	
	return self;
}

- (void)dealloc
{
	[wView release];
	[super dealloc];
}

- (void)setLoadingDelegate:(id)ld 
{
	dLoad = ld;
	NSLog(@"Set loading delegate.");
}

- (void)init
{
	[self _load:[NSURL URLWithString:@ROOT_URL]];
}

- (void)_load:(NSURL *)url
{
	NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url];
	[wView loadRequest:urlRequest];

	NSLog(@"Start loading URL.");
	
	isLoading = YES;
	if(dLoad != nil) [dLoad startLoading];
}

- (void)_execJS:(NSString *)script 
{
	[wView stringByEvaluatingJavaScriptFromString:script];
}


- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
	NSLog(@"Stop loading URL.");

	isLoading = NO;
	if(dLoad != nil) [dLoad stopLoading];
}

@end